<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cityList"></city-search>
        <city-list
        :hot="hotCityList"
        :cities="cityList"
        :letter="letter"
        ></city-list>
        <city-alphabet :cities="cityList"
        @change="handleLetterChange"
        ></city-alphabet>
    </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/header'
import CitySearch from './components/search'
import CityList from './components/list'
import CityAlphabet from './components/alphabet'
export default {
    name: 'City',
    data () {
        return {
            hotCityList: [],
            cityList: {},
            letter: ''
        }
    },
    components: {
        CityHeader,
        CitySearch,
        CityList,
        CityAlphabet
    },
    methods: {
        getCityInfo () {
            axios.get('/api/city.json')
                .then(this.getCityInfoSucc)
        },
        getCityInfoSucc (res) {
            res = res.data
            if (res.ret && res.data) {
                const data = res.data
                this.hotCityList = data.hotCities
                this.cityList = data.cities
            }
        },
        handleLetterChange (letter) {
            this.letter = letter
        }
    },
    mounted () {
        this.getCityInfo()
    }
}
</script>

<style lang="stylus" scoped>

</style>
